﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CashFlow.Web.MyActionResult;

using log4net;
using AutoFacUtils;
using CashFlow.Web.Service;

namespace CashFlow.Web.Filters
{
    public class NotLoginFilterAttribute : ActionFilterAttribute
    {
        private static ILog _logger = LogManager.GetLogger(typeof(NotLoginFilterAttribute));
        private IUserService GetUserService() { return AutoFacHelper.Get<IUserService>(); }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var service = GetUserService();
            if (service.IsLogin())
            {
                filterContext.HttpContext.Response.Clear();
                filterContext.Result = new RedirectResult("~/", false);
            }
        }
    }
}